﻿/*
Created By:     lixueming
Created When:   2012-4-6
why: 处理公用部分的头部信息
*/

//$('.login dt a').click(function () {
//    userlogin();
//});


var userlogin = function () {
    $.colorbox({
        href: "/" + g_siteroot + "/login.html",
        width: 428,
        height: 283
    });
    // return false;
}

var checkLogin = function () {
    var res = verifylogin();
    if (res != null & res.Result) {
        login_header();
    } else {
        logout_header();
    }
}

//验证登陆
var verifylogin = function () {
    var url = '/XmlHttpGate.aspx?cmd=Login_state&langID=' + g_langID + '&ram=' + new Date().toLocaleString();
    // alert(url);
    var resdata = null;
    jQuery.ajax({
        url: url,
        dataType: 'json',
        async: false,
        success: function (res) {
            resdata = res;
            return resdata;
        }
    });
    return resdata;
}

var userlogout = function () {
    //    if (confirm(globals.logout_tip)) 
    logout();
    logout_header();
    location.reload();
}

var logout = function () {
    var req = new requestCommand('Logout');
    req.async = false;
    req.get(function (data) {
    });
}

var logout_header = function () {
    //var req = new requestCommand('Logout');
    //req.async = false;
    var bLogout = null;
    var str = g_langID == 1033 ? 'Support sign with' : '快速登录';
    var Signin = g_langID == 2052 ? "登陆" : "Sign in";
    var Register = g_langID == 2052 ? "注册" : "Register";
    //req.get(function (data) {
        //bLogout = data;
        $(".searchform").parent().after().find("ol").remove();
        $(".personal").remove();
        var s = "";
        s += " <ol>";
        s += "            	<li>( " + str + "</li>";
        s += "                <li><a href=\"javascript:sg();\"><img src=\"/" + g_siteroot + "/images/icon_login_sina.gif\" alt=\"\"></a></li>";
        //s += "                <li><a href=\"javascript:void(0)\"><img src=\"/" + g_siteroot + "/images/icon_l_qq.gif\" alt=\"\"></a></li>";
        //s += "                <li><a href=\"javascript:void(0)\"><img src=\"/" + g_siteroot + "/images/icon_l_renren.gif\" alt=\"\"></a></li>";
        s += "                <li>)</li>";
        s += "         </ol>";
        $(".searchform").after(s);
        $(".logout").html("");
        s = "";
        s += " <dt><a href=\"javascript:userlogin();\" ><img src=\"/" + g_siteroot + "/images/btn_header_signin.gif\" alt=\""+Signin+"\"></a></dt>";
        s += " <dd><a href=\"/" + g_siteroot + "/register.html\"><img src=\"/" + g_siteroot + "/images/btn_header_register.gif\" alt=\""+Register+"\"></a></dd>";
        $(".logout").html(s);
        $(".logout").addClass("login");
        $(".logout").removeClass("logout");
    //});

    //    $('.login dt a').click(function () {
    //        userlogin();
    //    });

}

var login_header = function () {
    var member = getSessionMember();
    var AccountName = IsNull(member.Name);
    var MemberImg = IsNull(member.MemberImg);
    var showimg = globals.header_def;
    var myuknow = g_langID == 1033 ? 'My UK NOW' : '我的 UK NOW';
    //alert(showimg);
    if (MemberImg != "") {
        showimg = Environment.FilePath.UploadFrontImagePath + "/" + MemberImg;
    }

    $(".searchform").parent().after().find("ol").remove();
    var urlAccount = "/" + g_siteroot + "/myaccount.html";
    var s = "";
    s += "<dl class=\"personal\">";
    s += "<dt><a href=\"" + urlAccount + "\"><img src=\"" + showimg + "\" onerror='this.src=\"" + globals.header_def + "\"' height=\"28\" width=\"28\" alt=\"\"></a></dt>";
    s += "<dd>" + AccountName + "</dd>";
    s += "</dl>";
    $(".searchform").after(s);
    s = "";
    s += "<dt><a href=\"javascript:userlogout();\" >Logout</a></dt>";
    s += "<dd><a href=\"" + urlAccount + "\"><img src=\"/" + g_siteroot + "/images/btn_myuknow.gif\"  alt=\""+myuknow+" \"></a></dd>";
    $(".login").html(s);
    $(".login").addClass("logout");
    $(".login").removeClass("login");

}
function votshow() {
    var hf = (g_langID == 1033) ? "/en/vote.html" : "/cn/vote.html";
    $.colorbox({
        href: hf,
        width: 610,
        height: 605
    });

}